package cn.livingCloud.service.impl;

import cn.livingCloud.dto.UserFormDto;
import cn.livingCloud.dto.UserListDto;
import cn.livingCloud.entity.user.User;
import cn.livingCloud.repository.UserMapper;
import cn.livingCloud.service.UserService;
import cn.livingCloud.service.impl.operation.UserFormDtoUpdater;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by 唐旭 on 2015/12/2.
 */
@Service("userServiceImpl")
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    public void getUserList(UserListDto listDto) {
        listDto.addAllList(userMapper.findUserList(listDto));
    }

    public UserFormDto loadUserFormDto(String uuid) {
        if (StringUtils.isEmpty(uuid)) {
            return new UserFormDto();
        }
        User user = userMapper.findUserByUuid(uuid);
        return new UserFormDto(user);
    }

    public void editUser(UserFormDto formDto) {
        UserFormDtoUpdater updater = new UserFormDtoUpdater(formDto);
        updater.update();
    }
}
